SCC.150 Assembler Emulator
A compiler for a simple assembler language
 All Data Structures Files Functions
Functions
moonlander.c File Reference
#include "moonlander.h"

Functions

int main ()
 
void initialisencurses ()
 
void initialiseShip (SHIP *ship)
 
void initialiseLandscape (LANDSCAPE *landscape)
 
void createShip (SHIP *ship)
 
bool createLandscape (LANDSCAPE *landscape, unsigned int landscapeArray[], unsigned int safeArray[])
 
void applyJet (SHIP *ship, unsigned int dir)
 
void applyGravity (SHIP *ship)
 
void applyFriction (SHIP *ship)
 
void moveShip (SHIP *ship, size_t lASize, unsigned int landscapeArray[], size_t sASize, unsigned int safeArray[])
 
void displayIntro ()
 
double getScore (SHIP *ship, unsigned int time)
 

Detailed Description

Author
Ben Goldsworthy (rumps) bgold.nosp@m.swor.nosp@m.thy96.nosp@m.@gma.nosp@m.il.co.nosp@m.m
Version
1.0

LICENSE

This file is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This file is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

DESCRIPTION

This program attempts to emulate the 1979 Atari arcade classic 'Lunar Lander' in the *nix Terminal, using the ncurses library https://www.gnu.org/software/ncurses/ncurses.html. This can seemingly only be because Joe Finney is sadistic.

Implemented features so far are:

Features to implement by TOMORROW are:

Function Documentation

void applyFriction ( SHIP ship)

Applies the equally relentless force of friction to the ship.

Parameters
shipthe ship in question
void applyGravity ( SHIP ship)

Applies the relentless march of gravity to the ship.

Parameters
shipthe ship in question
void applyJet ( SHIP ship,
unsigned int  dir 
)

Applies the thrust of the jet to the ship.

If the ship is out of fuel, the jets won't fire.

Parameters
shipthe ship in question
dirthe thrust direction
bool createLandscape ( LANDSCAPE landscape,
unsigned int  landscapeArray[],
unsigned int  safeArray[] 
)

Creates the landscape in the game world.

Parameters
landscapethe landscape in question
landscapeArray[]the array of all the coordinates of the landscape components
safeArray[]the array of all the coordinates of the landing pad components
Returns
true if the landscape is valid (has at least one landing pad), false if not
void createShip ( SHIP ship)

Creates the ship in the game world.

Parameters
shipthe ship in question
void displayIntro ( )

Displays the lovely ASCII lunar lander I nicked.

double getScore ( SHIP ship,
unsigned int  time 
)

Works out the player's score upon successful landing.

The specification states "score is calculated using some heuristic based on time used and fuel remaining." Heuristic sounds fancy, and so is the method of working out the score.

Parameters
shipthe ship in question
Returns
the score
void initialiseLandscape ( LANDSCAPE landscape)

Initialises the landscape's parameters.

Parameters
landscapethe landscape in question
void initialisencurses ( )

Initialises ncurses.

I couldn't decide whether it should be initialisencurses(), initialiseNCURSES() or initialiseNcurses(). In the end I plumped for initialisencurses() because, whilst it does break the camelCase rule I've used throughout for variables and functions, ncurses is one of those trendy uncapitalised names.

void initialiseShip ( SHIP ship)

Initialises the ship's parameters.

Parameters
shipthe ship in question
int main ( )

The main function of the program.

Sets everything up initially, and then contains the game loop.

Returns
0 on success
void moveShip ( SHIP ship,
size_t  lASize,
unsigned int  landscapeArray[],
size_t  sASize,
unsigned int  safeArray[] 
)

Moves the ship within the game world.

Parameters
shipthe ship in question
lASizethe length of useful data in landscapeArray
landscapeArraythe array of coordinates for the components of the landscape
sASizethe length of useful data in safeArray
safeArraythe array of coordinates for the components of the landing pad(s)