Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Lezione27Novembre
- {
- class car
- {
- int speedMax;
- int retroMax; // velocità minima all'indietro (?)
- int speed;
- int currentGear; //marcia
- int maxGear;
- uint fuel;
- int[] gearChange;
- public car(int speedMax, int retroMax, int maxGear)
- {
- this.speed = 0;
- this.speedMax = speedMax;
- this.retroMax = retroMax;
- this.maxGear = maxGear;
- this.currentGear = 0;
- this.fuel = 100;
- gearChange = new int[maxGear +1]; //serve anche il folle, ecco perché c'è il +1. Manca la retromarcia però
- for(int i=0; i< maxGear + 1; i++)
- {
- gearChange[i] = i * (speedMax / maxGear);
- }
- }
- public void Accelerate()
- {
- if (fuel == 0)
- return;
- fuel--;
- if (currentGear == 0) //folle
- return;
- else if (currentGear < 0)
- {
- if (speed > retroMax) //torna indietro
- speed--;
- }
- else
- {
- if (speed < gearChange[currentGear])// va avanti
- speed++;
- //cambio manuale
- /* else if (speed == gearChange[currentGear]) ;
- GearUp();*/
- }
- }
- /*max speed: 100;
- 0:0;
- 1:50;
- 1:100;
- */
- //aumento della marcia
- public void GearUp()
- {
- if (currentGear < maxGear)
- currentGear++;
- }
- public void GearDown()
- {
- if (currentGear >= 0)
- currentGear--;
- }
- public void Brake() //lo chiamo quando premo il pedale del freno
- {
- if (speed == 0)
- return;
- if (speed > 0)
- speed--;
- else if (speed < 0)
- speed++;
- }
- public void ManageInput()
- {
- ConsoleKeyInfo key=Console.ReadKey();
- switch (key.Key)
- {
- case ConsoleKey.UpArrow:
- this.Accelerate();
- break;
- case ConsoleKey.Spacebar:
- this.Brake();
- break;
- case ConsoleKey.DownArrow:
- this.GearDown();
- break;
- case ConsoleKey.W:
- this.GearDown();
- break;
- }
- }
- public void Draw()
- {
- Console.WriteLine("Fuel: {0},", this.fuel);
- Console.WriteLine("Gear: {0},", this.currentGear);
- Console.WriteLine("Speed: {0},", this.speed);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement